<template>
	<!-- ant-card-bordered-->
	<view class="test-panel-controller">
		<view v-if="showImg" class="img-preview">
			<view class="img-preview-content">
				<image style="width: 80%!important;height:80%!important" mode="aspectFit" :src="`${$cdn}${cur_qs.img}`">
				</image>
			</view>
			<view style="width: 100%;display: flex;justify-content: center;">
				<button style="width: 20%;" @click="showImg=false">关闭</button>
			</view>
		</view>
		<view class="quesction-show-info ant-card-bordered">
			<view class="maxwidth">
				<a-typography-text type="secondary" :style="[getColor]">
					{{cur_qs.infoname}}--{{cur_qs.s_id}}
				</a-typography-text>
			</view>
			<view class="maxwidth" style="display: flex;" :style="[needResvoeFlex]">
				<block v-if="cur_qs.lang_txt=='WY' || cur_qs.lang_txt=='HY'">
					<p lang="ug" style="text-align: left;line-height: 66rpx;margin: 0px;" class="akf"
						:style="[getColor,getFontSetting,needResvoe]">
						{{cur_qs.q_desc}}
					</p>
					<p lang="zh" style="text-align: left;line-height: 66rpx;margin: 0px;"
						:style="[getColor,getFontSetting]">.{{cur_index+1}}</p>
				</block>
				<block v-else>
					<p style="text-align: left;line-height: 66rpx;margin:0px" :style="[getColor,getFontSettingOrg]">
						{{cur_index+1}}.{{cur_qs.q_desc}}
					</p>
				</block>
			</view>
			<view style="width: 100%;height: 32rpx;">
			</view>
			<checkbox-group @change="onCheckChange">
				<view style="display: flex;" class="maxwidth" v-for="(item,index) in cur_qs.q_struct"
					:style="[getColor,needResvoeFlex]">
					<block v-if="cur_qs.lang_txt=='WY' || cur_qs.lang_txt=='HY'">
						<block v-if="cur_qs.q_type!='2'">
							<p style="margin: 0px;" lang="ug" :style="[getColor,getFontSetting,needResvoe]" class="akf"
								v-if="cur_qs.q_type!='2'">
								{{item.value}}
							</p>
							<p lang="zh" style="text-align: left;line-height: 66rpx;margin:0px;"
								:style="[getColor,getFontSetting]">.{{label[index]}}</p>

							<checkbox v-if="cur_qs.q_type == '1'" :checked="cur_qs.check[index]" :value="index+''"
								:disabled="cur_qs.isright!=undefined">
							</checkbox>
						</block>
					</block>
					<block v-else>
						<checkbox v-if="cur_qs.q_type == '1'" :checked="cur_qs.check[index]" :value="index+''"
							:disabled="cur_qs.isright!=undefined">
						</checkbox>
						<p v-if="cur_qs.q_type!='2'" lang="zh" style="text-align: left;line-height: 66rpx;margin: 0px;"
							:style="[getColor,getFontSettingOrg]">
							{{label[index]}}. {{item.value}}
						</p>
					</block>
				</view>
			</checkbox-group>
		</view>
		<view class="quesction-ans-info ant-card-bordered" v-show="controllerStatus.SHOW_EXPLAN">
			<strong style="font-size: 16px;">
				{{cur_qs.q_analyse}}
			</strong>
		</view>
		<view class="quesction-controller-box ant-card-bordered">
			<!-- 		<a-typography-text class="tips" :style="[getFontSetting]">
				答题选项-多项选择选择完后请点击确定
			</a-typography-text> -->
			<view class="maxwidth ans">
				<a-row type="flex" style="align-items: baseline;">
					<a-col style="width: 70%;">
						<a-row style="align-items: center;">
							<view style="align-items:center;display: flex;min-width:150px;">
								<a-typography-text style="color: blue;">
									你的答案:
								</a-typography-text>
								<template v-if="cur_qs.showAns">
									<a-tag class="mtg" v-for="(item,index) in getChangeAns">
										{{item}}
									</a-tag>
								</template>
								<uni-icons style="margin-top:12rpx" :type="cur_qs.isright?'checkmarkempty':'closeempty'"
									:color="cur_qs.isright?'#36e206':'#ff1010'" size="32"
									v-if="controllerStatus.SHOW_RIGHT_OR_ERR && cur_qs.isright!=undefined">
								</uni-icons>
							</view>
							<view style="min-width:180px;"
								v-show="controllerStatus.SHOW_ANS && cur_qs.isright == false">
								<a-typography-text>
									正确答案:
								</a-typography-text>
								<a-tag v-for="(item,index) in textInfo[cur_qs.q_type].getAns(cur_qs)" class="mtg">
									{{item}}
								</a-tag>
							</view>
						</a-row>
					</a-col>
					<a-col class='change-controller'
						style="justify-content: center;display: flex;align-items: center;width: 30%;">
						<a-typography-text style="color: blue;">
							选择:
						</a-typography-text>
						<a-tag style="color: #000;!important" class="mtg" v-for="(item,index) in cur_qs.q_struct"
							:closable="false" @click="tiggerItem(item.index,index)">
							{{textInfo[cur_qs.q_type]['label'][index]}}
						</a-tag>
						<a-button v-if="cur_qs.q_type=='1'" @click="showAns(2)">确定</a-button>
					</a-col>
				</a-row>
			</view>
		</view>
		<view class="ant-card-bordered quesction-change-box">
			<a-skeleton active :loading="cur_qs==null">
			</a-skeleton>
			<a-row class="maxwidth" type="flex" v-if="cur_qs!=null" align="middle">
				<a-col flex="6">
					<a-row>
						<a-col :span="24">
							<a-typography-text style="color: red;">
								{{textInfo[cur_qs.q_type]['tips']}}
							</a-typography-text>
						</a-col>
					</a-row>
					<a-row>
						<a-col :span="24">
							<a-typography-text>
								请在备选答案中选择你认为正确的答案!
							</a-typography-text>
						</a-col>
					</a-row>
				</a-col>
				<a-col flex="7">
					<a-row type="flex" style="justify-content:center">
						<a-col style="margin-left: 32px;">
							<a-button @click="last()">上一题</a-button>
						</a-col>
						<a-col style="margin-left: 32px;">
							<a-button @click="next()">下一题</a-button>
						</a-col>
						<a-col style="margin-left: 32px;">
							<a-button @click="backPage">交卷</a-button>
						</a-col>
					</a-row>
				</a-col>
			</a-row>
		</view>
		<view class="quesction-img-box" v-if="imgUrl">
			<view class="imageshow-box">
				<!-- <a-image class="imageshow" :src="`${$cdn}${cur_qs.img}`" height="250" :preview="true" /> -->
				<img @click="isShowImg" :src="imgUrl" style="max-height:200px;max-width:800px;object-fit:scale-down;" />
			</view>
		</view>
	</view>
</template>

<script>
	import {
		Decimal
	} from 'decimal.js';
	import {
		mapGetters
	} from "vuex"
	let db = uniCloud.database()
	let dbCmd = db.command
	export default {
		name: "test-controller",
		props: {
			fontType: {
				default: 'SimHei',
				type: String
			},
			fontSize: {
				default: 20,
				type: Number
			},
			action: {
				default: 'CUSTMO',
				type: String
			},
			score: 0,
			controllerStatus: {
				"AUTO_PAGE": false,
				"RIGHT_PAGE": false,
				"SHOW_ANS": false,
				"SHOW_EXPLAN": false,
				"SHOW_RIGHT_OR_ERR": false,
				"SOUND_EXPLAN": false,
				"SOUND_QS": false,
				"SOUND_ON_ERR": false,
				"SOUND_RIGHT_OR_ERR": false,
				"TURN_PAGE": true,
				"AUTO_PAGE": false,
				"RIGHT_PAGE": false
			},
			quesctionlist: [Array],
			currentIndex: [Number],
			useCacheAns: false,
			rightNum: 0,
			errorNum: 0,
			szl: 0,
			ansArr: {},
			ans: null
		},
		watch: {
			'controllerStatus.SOUND_QS'(nv, ov) {
				if (nv) {
					this.openSoundQs()
					this.$emit('changeStatus', 'SOUND_QS', nv)
				}
			},
			'controllerStatus.SOUND_EXPLAN'(nv, ov) {
				if (nv) {
					this.openSoundExplan(nv)
					this.$emit('changeStatus', 'SOUND_EXPLAN', nv)
				}
			},
			'controllerStatus.TURN_PAGE'(nv) {
				if (nv) {
					this.$emit('changeStatus', 'TURN_PAGE', nv)
				}
			},
			'controllerStatus.AUTO_PAGE'(nv) {
				if (nv) {
					this.$emit('changeStatus', 'AUTO_PAGE', nv)
				}
			},
			'controllerStatus.RIGHT_PAGE'(nv) {
				if (nv) {
					this.$emit('changeStatus', 'RIGHT_PAGE', nv)
				}
			},
			cur_index(nv, ov) {
				this.$emit('update:currentIndex', nv)
			},
			r_num(nv) {
				this.$emit('update:rightNum', nv)
			},
			e_num(nv) {
				this.$emit('update:errorNum', nv)
			},
			data_szl(nv) {
				this.$emit('update:szl', nv)
			},
			cur_qs(n) {
				if (n.img) {
					this.imgUrl = this.$cdn + n.img
				} else {
					this.imgUrl = false
				}
			}
		},
		emits: ['submit', 'update:currentIndex', 'update:szl', 'update:rightNum', 'update:errorNum', 'changeStatus',
			'removeQueslist'
		],
		computed: {
			...mapGetters(['getUserInfo'])
		},
		data() {
			return {
				sz_score: 100,
				lang: 'CN',
				lastClick: 0,
				showImg: false,
				rightList: [],
				real_score: 0,
				r_num: 0,
				e_num: 0,
				data_szl: 0,
				errlist: {},
				errinfo: {},
				qs_ans_arr: {},
				qs_ans: [],
				cur_qs: null,
				label: ['A', 'B', 'C', 'D', 'E', 'F'],
				labelAns: {
					'0': 'A',
					'1': 'B',
					'2': 'C',
					'3': 'D',
					'4': 'E',
					'5': 'F'
				},
				AnsOfLable: {
					'A': '0',
					'B': '1',
					'C': '2',
					'D': '3',
					'E': '4',
					'F': '5',
				},
				//判断 为黑色、单选为蓝色、多选为红色。右侧题框里不显示试题序
				textInfo: {
					"0": {
						"value": 0,
						"text": "单选",
						"color": "#136cfa",
						"label": ['A', 'B', 'C', 'D', 'E', 'F'],
						"tips": "提示操作：单选题",
						"getAns": function(cur_qs) {
							if (cur_qs.realProps) {
								return [cur_qs.realProps.realAns]
							} else {
								return '出现异常，联系管理员CODE:7701'
							}
						},
						labelAns: {
							'0': 'A',
							'1': 'B',
							'2': 'C',
							'3': 'D',
							'4': 'E',
							'5': 'F'
						}
					},
					"1": {
						"value": 1,
						"text": "多选",
						"color": "#ff0000",
						"label": ['A', 'B', 'C', 'D', 'E', 'F'],
						"tips": "提示操作:多选题",
						"getAns": function(cur_qs) {
							if (cur_qs.realProps) {
								return cur_qs.realProps.realAns.split('|')
							} else {
								return '出现异常，联系管理员CODE:7702'
							}
						},
						labelAns: {
							'0': 'A',
							'1': 'B',
							'2': 'C',
							'3': 'D',
							'4': 'E',
							'5': 'F'
						},
					},
					"2": {
						"value": 2,
						"text": "判断",
						"color": "#000000",
						"label": ['√', '×'],
						"tips": "提示操作:判断选择题",
						"getAns": function(cur_qs) {
							let label = {
								'A': '√',
								'B': '×'
							}
							return [label[cur_qs.q_ans]]
						},
						labelAns: {
							'0': '√',
							'1': '×',
						},
					},
				},
				cur_index: 0,
				cur_ans_index: 0,
				err_ans_index: [],
				right_ans_index: [],
				user_ans_list: [],
				qs_typeText: [
					'单选',
					'多选',
					'简答'
				],
				soundTaskStatus: null,
				rightFileTempPath: 'right.mp3',
				errFileTempPath: "error.mp3",
				rightIndexList: [],
				imgUrl: false
			}
		},
		created() {
			console.log(this.quesctionlist)
			// console.log('created')
			// console.log('action', this.action)
			//console.log(this.quesctionlist[0])
			const self = this
			//	console.log(this.controllerStatus)
			this.qs_ans = this.ans
			this.qs_ans_arr = this.ansArr
			this.cur_index = this.currentIndex
			this.r_num = this.rightNum
			this.e_num = this.errorNum
			this.data_szl = this.szl
			if (this.cur_index > 0) {
				this.cur_qs = this.quesctionlist[this.cur_index]

			} else {
				this.cur_qs = this.quesctionlist[0]
			}

			// console.log('lang', this.cur_qs.lang_txt)

			if (this.cur_qs != undefined || this.cur_qs) {
				this.lang = this.cur_qs.lang_txt
			}
			this.errlist = new Set()
			this.errinfo = new Map()
			// uni.downloadFile({
			// 	url: self.$cdn+'right.mp3',
			// 	success: function(res) {
			// 		console.log(res)

			// 		self.rightFileTempPath = res.tempFilePath
			// 		uni.downloadFile({
			// 			url: self.$cdn+'error.mp3',
			// 			success: function(errRes) {
			// 				self.errFileTempPath = errRes.tempFilePath
			// 			}
			// 		})

			// 	}
			// })
		},
		mounted() {
			// console.log('mounted')
		},
		unmounted() {
			// console.log('destory component')
			if (this.soundTaskStatus != null) {
				this.soundTaskStatus.destroy()
			}
		},
		computed: {
			needResvoe() {
				if (this.cur_qs.lang_txt == 'WY' || this.cur_qs.lang_txt == 'HY') {
					return {
						direction: 'rtl',
						textAlign: 'right',
						unicodeBidi: 'isolate',
						justifyContent: 'flex-end'
					}
				} else {
					return false
				}
			},
			needResvoeFlex() {
				if (this.cur_qs.lang_txt == 'WY' || this.cur_qs.lang_txt == 'HY') {
					return {
						justifyContent: 'flex-end'
					}
				} else {
					return false
				}
			},
			getFontSetting() {
				return {
					fontSize: this.fontSize + 'px',
					fontFamily: 'ALKATIPTor',
				}
			},
			getFontSettingOrg() {
				return {
					fontSize: this.fontSize + 'px',
					fontFamily: 'Microsoft YaHei',
					fontWeight: "bold"
				}
			},
			getColor() {
				return {
					color: this.textInfo[this.quesctionlist[this.cur_index].q_type].color
				}
			},
			isRightCp() {
				if (this.cur_qs.q_type != '2') {
					if (!(this.getChangeAnsFn().join('|') === this.cur_qs.realProps.realAns)) {
						this.errlist.set(this.cur_qs.s_id)
						return false
					}
				} else {
					if (!(this.labelAns[this.qs_ans.join()] === this.cur_qs.q_ans)) {
						this.errlist.set(this.cur_qs.s_id)
						return false
					}
				}
				return true
			},
			getChangeAns() {
				let arr = []
				//let labArr [] 
				this.cur_qs.q_struct.forEach((e, i) => {
					if (this.qs_ans.includes(e.index)) {
						arr.push(this.textInfo[this.cur_qs.q_type]['labelAns'][`${i}`])
					}
				})
				return arr
			}
		},

		methods: {
			delInner() {
				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
					this.soundTaskStatus = null
				}
			},
			getSzl(count) {
				console.log(count)
				if (count === 0) {
					return 100
				}
				let maxScore = Decimal(100)
				let leng = Decimal(this.quesctionlist.length)
				let sign_score = maxScore.div(leng).toNumber().toFixed(2)
				let score = Decimal(100).sub(Decimal(sign_score).mul(count).toNumber().toFixed(2)).toNumber().toFixed(2)
				return score
			},
			getQsDesc(item) {
				if (this.cur_qs.lang_txt == 'HY' || this.cur_qs.lang_txt == 'WY') {
					return item.split('').reverse().join("")
				} else {
					return item
				}
			},
			isShowImg() {

				this.showImg = true
				return
				let now = (new Date).getTime()
				if (this.lastClick === 0) {
					this.lastClick = now
					setTimeout(() => {
						this.lastClick = 0
					}, 400)
					return
				}
				let clickTimes = now - this.lastClick
				if (clickTimes < 400 && clickTimes > 0) {
					this.showImg = true
				}
			},
			backPage() {
				this.$emit('submit', 'NOT_CACHE')
			},
			/**
			 * 只计算做错的，并且累加,在当前题目中做对也不算,如果是从我的错题ACTION进入需要删除当前作对的题目
			 */
			saveCache(cacheType) {
				const self = this
				const userinfo = uni.getStorageSync('userinfo')
				let errlist = []
				let errlistremove = []
				for (let s of this.errlist.values()) {
					let test_name = this.errinfo.get(s).test_name
					errlist.push({
						q_id: s,
						test_name
					})
					errlistremove.push(s)
				}
				// let cacheData = {
				// 	errorlist:errlist,
				// 	 cachedata: {
				// 		r_num: self.r_num,
				// 		e_num: self.e_num, 
				// 		qlist: JSON.stringify(self.quesctionlist),
				// 		ans: self.qs_ans_arr,
				// 		cur_index: self.cur_index,
				// 		cur_ans: self.qs_ans
				// 	},
				// 	cacheType: 'DEFAULT',
				// 	uid:this.getUserInfo
				// }

				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
				}
				if (errlist.length > 0 && this.action != 'ERROR_LIST') {
					db.collection('error-qlist').where({
						q_id: db.command.in(errlistremove),
						user_id: userinfo._id
					}).remove().then(res => {
						db.collection('error-qlist').add(errlist).then(errAddres => {
							console.log('增加错题', errAddres)
						})
					})
				}

				const formdata = {
					cachedata: {
						r_num: self.r_num,
						e_num: self.e_num,
						qlist: self.quesctionlist,
						ans: self.qs_ans_arr,
						cur_index: self.cur_index,
						cur_ans: self.qs_ans,
						score: 0
					},
					'cacheType': 'DEFAULT'
				}

				uniCloud.callFunction({
					name: 'saveHistoryv2',
					data: {
						saveData: JSON.stringify(formdata)
					}
				}).then(res => {
					console.log('save status', res)
				})

				return
				console.log('userid', userinfo._id)
				// if (userinfo._id)
				// 	db.collection('test-history').where({
				// 		user_id: dbCmd.eq(userinfo._id)
				// 	}).remove().then(res => {
				// 		return 'ok'
				// 	}).then(res => {
				// 		db.collection('test-history')
				// 			.add({
				// 				cachedata: {
				// 					r_num: self.r_num,
				// 					e_num: self.e_num,
				// 					qlist: self.quesctionlist,
				// 					ans: self.qs_ans_arr,
				// 					cur_index: self.cur_index,
				// 					cur_ans: self.qs_ans
				// 				},
				// 				'cacheType': 'DEFAULT'
				// 			}).then(code => {})
				// 	})

			},
			resetError(firstData) {
				const self = this
				try {
					// this.removeQueslist()

					let status = uni.getStorageSync('iserror')
					if (status) {
						try {
							for (let s of this.quesctionlist) {
								delete s.showAns
								delete s.isright
								delete s.ansLabel
								delete s.ukeys
								if (s.check) {
									s.check = [false, false, false, false, false, false]
									s.hasError = true
									s.haschange = false
								}
							}
							if (self.soundTaskStatus) {
								self.soundTaskStatus.destroy()
							}
							self.qs_ans = []
							self.r_num = 0
							self.e_num = 0
							self.data_szl = 100
							self.qs_ans_arr = {}
							self.cur_index = 0
							self.cur_qs = firstData
							self.$forceUpdate()
						} catch (e) {
							console.log('err', e)
						}


					}

				} catch (e) {
					console.log(e)
				}

			},
			resetAll() {


				for (let s of this.quesctionlist) {
					delete s.showAns
					delete s.isright
					delete s.ansLabel
					delete s.ukeys
					if (s.check) {
						s.check = [false, false, false, false, false, false]
						s.hasError = true
						s.haschange = false
					}
				}


				this.cur_index = 0
				this.cur_qs = this.quesctionlist[0]
				this.qs_ans = []
				this.r_num = 0
				this.e_num = 0
				this.qs_ans_arr = {}


			},
			createdAudio: function(url) {
				// console.log(url)

				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
					this.soundTaskStatus = null
				}

				this.soundTaskStatus = uni.createInnerAudioContext();
				this.soundTaskStatus.autoplay = true;
				this.soundTaskStatus.src = this.$cdn + url
				this.soundTaskStatus.onPlay(() => {
					//	console.log('开始播放');
				});
				this.soundTaskStatus.onError((res) => {
					console.log('error sound')
					// uni.showModal({
					// 	title: '资源无法访问!',
					// 	content: '资源无法访问!'
					// })
				});
			},
			openSoundQs: function(force = false) {
				// console.log(this.controllerStatus.SOUND_QS)
				if (this.controllerStatus.SOUND_QS == false && force == false) {
					return
				}
				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
				}
				if (!this.cur_qs.auto_sound) {
					uni.showToast({
						title: '此题暂无音频讲解',
						duration: 2000,
						icon: 'none'
					})
					return
				}
				this.createdAudio('sound/' + this.cur_qs.auto_sound)
			},
			openSoundExplan(status) {
				// console.log('run error lis', status)
				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
				}
				if (status) {
					if (!this.cur_qs.sound) {
						uni.showToast({
							title: '此题暂无音频讲解',
							duration: 2000,
							icon: 'none'
						})
						return
					}
					this.createdAudio(this.cur_qs.sound)
				}
			},
			getChangeAnsFn() {
				let arr = []
				this.cur_qs.q_struct.forEach((e, i) => {
					if (this.qs_ans.includes(e.index)) {
						arr.push(this.textInfo[this.cur_qs.q_type]['labelAns'][`${i}`])
					}
				})
				arr.sort()
				return arr
			},
			isRightFn() {
				let ans = ''
				let ans_status = true

				if (this.cur_qs.q_type != '2') {
					ans = this.getChangeAnsFn().join('|')
					if (!(ans === this.cur_qs.realProps.realAns)) {
						ans_status = false

						if (this.cur_qs.ukeys === undefined) {
							this.$set(this.cur_qs, 'ukeys', false)
						}

						this.errlist.add(this.cur_qs.s_id)
						this.errinfo.set(this.cur_qs.s_id, {
							test_name: this.cur_qs.testpaper_name
						})
						//	console.log(this.errinfo)
					}
				} else {
					ans = this.labelAns[this.qs_ans.join()]
					if (!(ans === this.cur_qs.q_ans)) {
						ans_status = false
						if (this.cur_qs.ukeys === undefined) {
							this.$set(this.cur_qs, 'ukeys', false)
						}
						this.errlist.add(this.cur_qs.s_id)
						this.errinfo.set(this.cur_qs.s_id, {
							test_name: this.cur_qs.testpaper_name
						})
						//	console.log(this.errinfo)

					}
				}

				if (this.cur_qs.ukeys === undefined && ans_status) {
					this.$set(this.cur_qs, 'ukeys', true)
				}

				if (this.cur_qs.isright === false && ans_status === true) {
					this.$set(this.cur_qs, 'hasError', false)
				}

				if (this.cur_qs.hasError === false && ans_status === false) {
					this.$set(this.cur_qs, 'hasError', true)
				}


				this.cur_qs.isright = ans_status
				let errorRightCount = this.getRightErrorCount()

				let count = this.getFirstErrorCount()
				let score = this.getSzl(count)
				this.r_num = errorRightCount[0]
				this.e_num = errorRightCount[1]
				this.data_szl = score
				this.$emit('update:szl', this.data_szl)
				// if (ans_status) {
				// 	if (this.rightList.indexOf(this.cur_qs.s_id) === -1) {
				// 		this.rightList.push(this.cur_qs.s_id)
				// 		this.rightIndexList.push(this.cur_index)
				// 	}
				// 	console.log('rightlist',this.righlis)
				// }

				if (this.cur_qs.q_type == '2') {
					this.cur_qs.ansLabel = ans == 'A' ? '√' : "✘"
				} else {
					this.cur_qs.ansLabel = this.getChangeAnsFn().join('')
				}

				if (this.controllerStatus.AUTO_PAGE) {
					this.next()
					return
				}
				if (this.controllerStatus.RIGHT_PAGE && ans_status == true) {
					this.next()
					return
				}
				if (this.controllerStatus.SOUND_RIGHT_OR_ERR) {
					let url = ans_status ? this.rightFileTempPath : this.errFileTempPath
					this.createdAudio(url)
				}
				if (this.controllerStatus.SOUND_ON_ERR && ans_status == false) {
					this.createdAudio(this.cur_qs.sound)
				}
				this.cur_qs.haschange = true
			},
			getFirstErrorCount() {
				let num = 0
				for (let s of this.quesctionlist) {
					if (s.ukeys !== undefined && s.ukeys === false) {
						num++
					}
				}
				console.log(num)
				return num
			},
			getRightErrorCount() {
				let right = 0
				let error = 0
				for (let s of this.quesctionlist) {
					if (s.isright === true) {
						right++
					}
					if (s.isright === false) {
						error++
					}
				}
				return [right, error]
			},
			isError() {},
			onCheckChange(e) {
				let ans_temp = []
				for (let s of e.detail.value) {
					let target = this.cur_qs.q_struct[s].index
					ans_temp.push(target)
				}
				this.qs_ans = ans_temp
				this.qs_ans_arr[this.cur_qs.s_id] = this.qs_ans
				if (this.cur_qs.q_type == '1') {
					for (let s of e.detail.value) {
						this.cur_qs.check[s] = true
					}
				}
			},

			next() {
				const self = this
				// console.log(this.cur_qs.q_type)
				if (this.cur_qs.q_type == '1') {
					// console.log(this.qs_ans)

					// if (Object.keys(this.qs_ans).length == 0) {
					// 	uni.showModal({
					// 		content: '你还没有选择答案'
					// 	})
					// 	return
					// }
				}

				if (this.cur_index < this.quesctionlist.length - 1) {
					this.skipQs(this.cur_index + 1)
				} else {
					uni.showModal({
						content: '是否提交?',
						title: 'tips',
						success(res) {
							if (res.confirm) {
								self.backPage()
								//	self.totalNumber()
								//	self.submitStatus = true
								//	self.allStatus = true

							}
						}
					})
				}
			},
			last() {
				if (this.cur_index != 0) {
					// if (this.cur_qs.q_type == '1') {
					// 	if (Object.keys(this.qs_ans).length == 0) {
					// 		uni.showModal({
					// 			content: '你还没有选择答案'
					// 		})
					// 		return
					// 	}
					// }
					//this.set_loc_history(this.cur_qs_id)
					this.skipQs(this.cur_index - 1)
				}
			},
			skipQs(index, action) {
				//	console.log(index)
				//先保存当前数据
				//	this.set_loc_history(this.cur_qs_id)
				//切换下一条数据
				//	this.cur_qs_id = this.user_ans_list[index]._id
				if (this.cur_index === index) {
					return
				}

				if (this.cur_qs.q_type == '1' && this.cur_qs.isright == undefined) {
					this.showAns(2)
				}

				this.cur_index = index
				// if (action === 'pop') {
				// 	this.$refs.popup.close()
				// }
				// console.log(this.soundTaskStatus)
				this.resetStatus()
				// this.cur_qs = this.quesctionlist[this.cur_index]
				this.$set(this, 'cur_qs', this.quesctionlist[this.cur_index])
				// console.log(this.cur_qs)
				this.getCurrQsStatus()
				this.openSoundExplan(this.controllerStatus.SOUND_EXPLAN)
				this.openSoundQs()

				if (this.cur_qs != undefined || this.cur_qs) {
					this.lang = this.cur_qs.lang_txt
				}
				this.$forceUpdate()
			},
			resetStatus() {
				this.qs_ans_arr[this.cur_qs.s_id] = this.qs_ans
				this.qs_ans = []
				if (this.soundTaskStatus) {
					this.soundTaskStatus.destroy()
					this.soundTaskStatus = null
				}
				//	console.log(this.qs_ans_arr)
			},
			getCurrQsStatus() {
				if (this.qs_ans_arr[this.cur_qs.s_id]) {
					this.qs_ans = this.qs_ans_arr[this.cur_qs.s_id]
				}
			},
			tiggerItem(id, checkIndex) {
				// console.log('run tiggerItem')
				// console.log(id, checkIndex)
				// if (this.cur_qs.showAns) {
				// 	return
				// }
				const position = this.qs_ans.indexOf(id)

				if (this.qs_ans.length >= 1 && this.cur_qs.q_type != '1') {
					this.qs_ans = []
				}
				if (position === -1) {
					this.qs_ans.push(id)
					this.qs_ans_arr[this.cur_qs.s_id] = this.qs_ans

				} else {
					this.qs_ans.splice(position, 1)
					this.qs_ans_arr[this.cur_qs.s_id] = this.qs_ans
				}
				if (this.cur_qs.q_type == '1') {
					//	console.log(this.cur_qs.check[checkIndex])
					this.cur_qs.check[checkIndex] = !this.cur_qs.check[checkIndex]
					// console.log(this.cur_qs.check)
					// this.$set(this.cur_qs.check,checkIndex,!this.cur_qs.check[checkIndex])
					// console.log(this.cur_qs.check)
				} else {
					if (this.cur_qs.check[checkIndex] == true) {
						this.$set(this.cur_qs.check, checkIndex, false)
						return
					}

					for (let position of [0, 1, 2, 3]) {
						this.$set(this.cur_qs.check, position, false)
					}
					this.$set(this.cur_qs.check, checkIndex, true)
				}
				this.showAns()
			},
			showAns(type) {
				// console.log('show ans', this.cur_qs.q_type)
				if (this.cur_qs.q_type != 1) {
					this.$set(this.cur_qs, 'showAns', true)
					this.isRightFn()
				}
				if (type) {
					if (Object.keys(this.qs_ans).length == 0) {
						// uni.showModal({
						// 	content: '你还没有选择答案'
						// })
						return
					}
					this.$set(this.cur_qs, 'showAns', true)
					this.isRightFn()
				}
			},
			removeQueslist() {
				this.$emit('removeQueslist')
				this.rightIndexList = []
				this.rightList = []

			}
		},
	}
</script>

<style scoped lang="scss">
	@import url('./testcontroller.css');
</style>
